import { SHOPLIST_GET_DATA } from '../mutation-types';
import { getShopCategoryList } from '../../api';
// import request from '../../utils/wxRequest';

const state = {
  data: {},
  loading: true,
  noMore: true,
  noData: true
};

const getters = {
  data: (state) => state.data,
  loading: (state) => state.loading,
  nomore: (state) => state.noMore,
  nodata: (state) => state.noData
};

const mutations = {
  [SHOPLIST_GET_DATA](state, payload) {
    state.data = payload.data;
    state.loading = false;
    state.noMore = false;
    state.noData = true;
  }
};

const actions = {
  [SHOPLIST_GET_DATA]({ commit }, data) {
    console.log('todo');
    console.log(data.id);
    getShopCategoryList(data.id, data.page)
      .then(res => {
        console.log(res);
        commit({
          type: SHOPLIST_GET_DATA,
          data: res.data
        });
      })
      .catch(e => {
        console.log(e);
      });
  }
};

export default {
  namespaced: true,
  state,
  getters,
  mutations,
  actions
};
